<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0,
           maximum-scale=1.0, minimum-scale=1.0"/>
    <title>angular实现缓存($cacheFactory)</title>
    <style>
        #parent div{
            width: 300px;
            height: 500px;
            border: 1px #000 solid;
            margin: 20px;
        }
        #parent ul{
            width: 200px;
            position: fixed;
            top: 0;
            right: 0;
        }
    </style>

    <script src="js/angular.js"></script>
</head>
<body>
    <div ng-app="myApp">
        <div id="parent" ng-controller="fristControl">
            <ul>
                <li ng-repeat="id in [1,2,3,4,5]" ng-click="change('div'+id)">{{id}}aaa</li>
            </ul>
            <div ng-repeat="id in [1,2,3,4,5]" ng-attr-id="div{{id}}">{{id}}</div>
        </div>

        <div  ng-controller="secondControl">

        </div>
    </div>
</body>
<script>
    /*说明
    * $cacheFactory 是缓存的作用用点像 android中的sharprefence;
    * */
    var app=angular.module('myApp',[]);
    app.controller("fristControl",['$scope','$cacheFactory',
        function ($scope, $cacheFactory) {
            var cache=$cacheFactory('cacheId');
            cache.put('name',"zhangsan");
//            var name=cache.get("name");
//            console.log(name);
    }]);

    app.controller('secondControl',['$scope','$cacheFactory',
        function ($scope, $cacheFactory) {
            //通过之前定义的cacheId，拿到cache对象，然后在获取,这样shi先了缓存效果;
            var cache=$cacheFactory.get('cacheId');
            var name=cache.get("name");
            console.log(name);
    }]);
</script>
</html>